﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Framework;
using OLTS.DAL;
using OLTS.MODEL;

namespace OLTS.DATA_SERVICE
{
    public class Holiday_Service
    {
        private String _year = String.Empty;
        private int _siteId = 0;
        private OTS_HOLIDAY _objApp;
        public Holiday_Service(String year, int siteId)
        {
            _year = year;
            _siteId = siteId;
        }
        public Holiday_Service(OTS_HOLIDAY objApp)
        {
            _objApp = objApp;          
        }
        public List<OTS_HOLIDAY> GetListHoliday()
        {
            using (var ctx = new Entities())
            {
                var res = new List<OTS_HOLIDAY>();
                res = ctx.OTS_HOLIDAY.Where(x => x.SITE_ID == _siteId && x.YEAR == _year).ToList();
                return res;
            }
        }
        public void Add()
        {
            using (var ctx = new Entities())
            {
                ctx.OTS_HOLIDAY.AddObject(_objApp);
                ctx.SaveChanges();
            }
        }
        public void Edit()
        {
            using (var ctx = new Entities())
            {
                var obj = ctx.OTS_HOLIDAY.Where(x => x.ID == _objApp.ID).FirstOrDefault();
                obj.DATE = _objApp.DATE;
                obj.NAME = _objApp.NAME;
                ctx.SaveChanges();
            }
        }
        public void Delete()
        {
            using (var ctx = new Entities())
            {
                var obj = ctx.OTS_HOLIDAY.Where(x => x.ID == _objApp.ID).FirstOrDefault();
                ctx.OTS_HOLIDAY.DeleteObject(obj);
                ctx.SaveChanges();
            }
        }
    }
}
